package com.tsh.chat.service.impl;

import com.tsh.chat.domain.ChatHistory;
import com.tsh.chat.domain.Personality;
import com.tsh.chat.domain.PromptHistory;
import com.tsh.chat.mapper.PersonalitySimulatorMapper;
import com.tsh.chat.service.PersonalitySimulatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonalitySimulatorServiceImpl implements PersonalitySimulatorService {
    @Autowired
    private PersonalitySimulatorMapper personalitySimulatorMapper;

    @Override
    public int getLastInsertId(){
        return personalitySimulatorMapper.selectLastInsertId();
    }

    @Override
    public List<Personality> getPersonality(int userId){
        return personalitySimulatorMapper.selectPersonalityById(userId);
    }

    @Override
    public int insertPersonality(Personality personality){
        return personalitySimulatorMapper.insertPersonality(personality);
    }

    @Override
    public int updatePersonality(Personality personality){
        return personalitySimulatorMapper.updatePersonality(personality);
    }

    @Override
    public int deletePersonality(int id){
        return personalitySimulatorMapper.deletePersonality(id);
    }

    @Override
    public int deletePromptHistoryById(int id){
        return personalitySimulatorMapper.deletePromptHistoryById(id);
    }

    @Override
    public int deletePromptHistoryByUserId(int userId){
        return personalitySimulatorMapper.deletePromptHistoryByUserId(userId);
    }

    @Override
    public int insertPromptHistory(int userId, String prompt){
        PromptHistory promptHistory = new PromptHistory();
        promptHistory.setUserId(userId);
        promptHistory.setPrompt(prompt);
        return personalitySimulatorMapper.insertPromptHistory(promptHistory);
    }

    @Override
    public int updatePromptHistory(PromptHistory promptHistory){
        return personalitySimulatorMapper.updatePromptHistory(promptHistory);
    }

    @Override
    public List<PromptHistory> getPromptHistoryByUserId(int userId){
        return personalitySimulatorMapper.selectPromptHistoryByUserId(userId);
    }

    @Override
    public List<PromptHistory> getAllPromptHistory(){
        return personalitySimulatorMapper.selectAllPromptHistories();
    }

    @Override
    public List<ChatHistory> getChatHistoryByUserId(int userId){
        return personalitySimulatorMapper.findChatHistoryByUserId(userId);
    }

    @Override
    public int insertChatHistory(int user_id, String role, String content){
        ChatHistory chatHistory = new ChatHistory();
        chatHistory.setUser_id(user_id);
        chatHistory.setRole(role);
        chatHistory.setContent(content);
        return personalitySimulatorMapper.insertChatHistory(chatHistory);
    }

    @Override
    public int updateChatHistory(ChatHistory chatHistory){
        return personalitySimulatorMapper.updateChatHistory(chatHistory);
    }

    @Override
    public int deleteChatHistoryByUserId(int userId){
        return personalitySimulatorMapper.deleteChatHistoryByUserId(userId);
    }
}
